package com.kunlun.baseconf;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 
/**
 * @Author: Eric
 *
 **/ 
@Configuration 
public class WebMvcConfig extends WebMvcConfigurationSupport {
	
    @Autowired
    private LoginInterceptor loginInterceptor;
	
	@Override 
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		//将templates目录下的CSS、JS文件映射为静态资源，防止Spring把这些资源识别成thymeleaf模版 
		registry.addResourceHandler("/templates/**.js").addResourceLocations("classpath:/templates/"); 
		registry.addResourceHandler("/templates/**.css").addResourceLocations("classpath:/templates/"); 
		//其他静态资源 
		registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); 
	} 
	
//	@Override
//    public void addViewControllers(ViewControllerRegistry registry) {
//	        registry.addViewController("/").setViewName("index");
//	        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
//	        super.addViewControllers(registry);
//	}
	
	
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // addPathPatterns("/**") 表示拦截所有的请求，
        // excludePathPatterns("/login", "/register") 表示除了登陆与注册之外，因为登陆注册不需要登陆也可以访问
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns("/login","/loginCheck","/login.html", "/register");
        super.addInterceptors(registry);
    }
 
	
}
 
